<article id="wikiArticle">
<div> <div class="blockIndicator deprecated deprecatedHeader">
<p><strong><span class="icon-only-inline" title="This is an obsolete API and is no longer guaranteed to work."><i class="icon-trash"> </i></span> 已废弃</strong><br/>该特性已经从 Web 标准中删除，虽然一些浏览器目前仍然支持它，但也许会在未来的某个时间停止支持，请尽量不要使用该特性。</p>
</div></div>
<p><strong><code>sup()</code></strong>方法创建 一个<a href="/zh-CN/docs/Web/HTML/Element/sup" title="HTML &lt;sup&gt; 元素定义了一个文本区域，出于排版的原因，与主要的文本相比，应该展示得更高并且更小。"><code>&lt;sup&gt;</code></a>HTML 元素，使字符串显示为上标。</p>
<h2 id="语法">语法</h2>
<pre><code class="language-javascript"><code><var>str</var>.sup()</code></code></pre>
<h3 id="返回值">返回值</h3>
<p>包含<a href="/zh-CN/docs/Web/HTML/Element/sup" title="HTML &lt;sup&gt; 元素定义了一个文本区域，出于排版的原因，与主要的文本相比，应该展示得更高并且更小。"><code>&lt;sup&gt;</code></a> HTML 元素的字符串。</p>
<h2 id="描述">描述</h2>
<p><code>sup()</code> 方法将字符串嵌入 <code>&lt;sup&gt;</code> 标签中：<code>"&lt;sup&gt;str&lt;/sup&gt;"</code>.</p>
<h2 id="示例">示例</h2>
<h3 id="使用sub()和sup()方法">使用<code>sub()</code>和<code>sup()</code>方法</h3>
<p>下面的示例使用了<a href="Reference/Global_Objects/String/sub" title="sub()方法创建一个 &lt;sub&gt; HTML 元素，使字符串展示为下标。"><code>sub()</code></a>和<code>sup()</code>方法来格式化字符串：</p>
<pre><code  class="language-javascript">var superText = 'superscript';
var subText = 'subscript';

console.log('This is what a ' + superText.sup() + ' looks like.');
// "这就是&lt;sup&gt;superscript&lt;/sup&gt;的样子。"

console.log('This is what a ' + subText.sub() + ' looks like.');
// "这就是&lt;sub&gt;subscript&lt;/sub&gt;的样子。"
</code></pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-string.prototype.sup" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">String.prototype.sup</small></a></td>
<td><span class="spec-Standard">Standard</span></td>
<td>初始定义。在 JavaScript 1.0 中实现。在（规范性）附件 B 中定义为用于 Web 浏览器的 ECMAScript 附加特性。</td>
</tr>
<tr>
<td><a class="external" href="https://tc39.github.io/ecma262/#sec-string.prototype.sup" hreflang="en" lang="en" rel="noopener">ECMAScript Latest Draft (ECMA-262)<br/><small lang="zh-CN">String.prototype.sup</small></a></td>
<td><span class="spec-Draft">Draft</span></td>
<td>在（规范性）附件 B 中定义为用于 Web 浏览器的 ECMAScript 附加特性。</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
            This compatibility table still uses the old format,
            because we haven't yet converted the data it contains.
            <strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
<div class="htab">
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
<ul>
<li class="selected"><a>Desktop</a></li>
<li><a>Mobile</a></li>
</ul>
</div></div>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Chrome</th>
<th>Firefox (Gecko)</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td>1.0 (1.7 or earlier)</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Android</th>
<th>Chrome for Android</th>
<th>Firefox Mobile (Gecko)</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td>1.0 (1.0)</td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
</tr>
</tbody>
</table>
</div>
<h2 id="另见">另见</h2>
<ul>
<li><a href="Reference/Global_Objects/String/sub" title="sub()方法创建一个 &lt;sub&gt; HTML 元素，使字符串展示为下标。"><code>String.prototype.sub()</code></a></li>
</ul>
</article>